/*
@license
dhtmlxScheduler.Net v.3.3.23 Professional Evaluation

This software is covered by DHTMLX Evaluation License. Contact sales@dhtmlx.com to get Commercial or Enterprise license. Usage without proper license is prohibited.

(c) Dinamenta, UAB.
*/
Scheduler.plugin(function(e){e.attachEvent("onTemplatesReady",function(){this.layers.sort(function(e,t){return e.zIndex-t.zIndex}),e._dp_init=function(t){t._methods=["_set_event_text_style","","changeEventId","deleteEvent"],this.attachEvent("onEventAdded",function(e){!this._loading&&this.validId(e)&&this.getEvent(e)&&this.getEvent(e).layer==t.layer&&t.setUpdated(e,!0,"inserted")}),this.attachEvent("onBeforeEventDelete",function(e){if(this.getEvent(e)&&this.getEvent(e).layer==t.layer){if(!this.validId(e))return;

var a=t.getState(e);return"inserted"==a||this._new_event?(t.setUpdated(e,!1),!0):"deleted"==a?!1:"true_deleted"==a?!0:(t.setUpdated(e,!0,"deleted"),!1)}return!0}),this.attachEvent("onEventChanged",function(e){!this._loading&&this.validId(e)&&this.getEvent(e)&&this.getEvent(e).layer==t.layer&&t.setUpdated(e,!0,"updated")}),t._getRowData=function(e,t){var a=this.obj.getEvent(e),n={};for(var i in a)0!==i.indexOf("_")&&(n[i]=a[i]&&a[i].getUTCFullYear?this.obj.templates.xml_format(a[i]):a[i]);return n;

},t._clearUpdateFlag=function(){},t.attachEvent("insertCallback",e._update_callback),t.attachEvent("updateCallback",e._update_callback),t.attachEvent("deleteCallback",function(e,t){this.obj.setUserData(t,this.action_param,"true_deleted"),this.obj.deleteEvent(t)})},function(){var t=function(e){if(null===e||"object"!=typeof e)return e;var a=new e.constructor;for(var n in e)a[n]=t(e[n]);return a};e._dataprocessors=[],e._layers_zindex={};for(var a=0;a<e.layers.length;a++){if(e.config["lightbox_"+e.layers[a].name]={},
e.config["lightbox_"+e.layers[a].name].sections=t(e.config.lightbox.sections),e._layers_zindex[e.layers[a].name]=e.config.inital_layer_zindex||5+3*a,e.layers[a].url){var n=new dataProcessor(e.layers[a].url);n.layer=e.layers[a].name,e._dataprocessors.push(n),e._dataprocessors[a].init(e)}e.layers[a].isDefault&&(e.defaultLayer=e.layers[a].name)}}(),e.showLayer=function(e){this.toggleLayer(e,!0)},e.hideLayer=function(e){this.toggleLayer(e,!1)},e.toggleLayer=function(e,t){var a=this.getLayer(e);a.visible="undefined"!=typeof t?!!t:!a.visible,
this.setCurrentView(this._date,this._mode)},e.getLayer=function(t){var a,n;"string"==typeof t&&(n=t),"object"==typeof t&&(n=t.layer);for(var i=0;i<e.layers.length;i++)e.layers[i].name==n&&(a=e.layers[i]);return a},e.attachEvent("onBeforeLightbox",function(t){var a=this.getEvent(t);return this.config.lightbox.sections=this.config["lightbox_"+a.layer].sections,e.resetLightbox(),!0}),e.attachEvent("onClick",function(t,a){var n=e.getEvent(t);return!e.getLayer(n.layer).noMenu}),e.attachEvent("onEventCollision",function(t,a){
var n=this.getLayer(t);if(!n.checkCollision)return!1;for(var i=0,r=0;r<a.length;r++)a[r].layer==n.name&&a[r].id!=t.id&&i++;return i>=e.config.collision_limit}),e.addEvent=function(t,a,n,i,r){var l=t;1!=arguments.length&&(l=r||{},l.start_date=t,l.end_date=a,l.text=n,l.id=i,l.layer=this.defaultLayer),l.id=l.id||e.uid(),l.text=l.text||"","string"==typeof l.start_date&&(l.start_date=this.templates.api_date(l.start_date)),"string"==typeof l.end_date&&(l.end_date=this.templates.api_date(l.end_date)),l._timed=this.isOneDayEvent(l);

var d=!this._events[l.id];this._events[l.id]=l,this.event_updated(l),this._loading||this.callEvent(d?"onEventAdded":"onEventChanged",[l.id,l])},this._evs_layer={};for(var t=0;t<this.layers.length;t++)this._evs_layer[this.layers[t].name]=[];e.addEventNow=function(t,a,n){var i={};"object"==typeof t&&(i=t,t=null);var r=6e4*(this.config.event_duration||this.config.time_step);t||(t=Math.round(e._currentDate().valueOf()/r)*r);var l=new Date(t);if(!a){var d=this.config.first_hour;d>l.getHours()&&(l.setHours(d),
t=l.valueOf()),a=t+r}i.start_date=i.start_date||l,i.end_date=i.end_date||new Date(a),i.text=i.text||this.locale.labels.new_event,i.id=this._drag_id=this.uid(),i.layer=this.defaultLayer,this._drag_mode="new-size",this._loading=!0,this.addEvent(i),this.callEvent("onEventCreated",[this._drag_id,n]),this._loading=!1,this._drag_event={},this._on_mouse_up(n)},e._t_render_view_data=function(e){if(this.config.multi_day&&!this._table_view){for(var t=[],a=[],n=0;n<e.length;n++)e[n]._timed?t.push(e[n]):a.push(e[n]);

this._table_view=!0,this.render_data(a),this._table_view=!1,this.render_data(t)}else this.render_data(e)},e.render_view_data=function(){if(this._not_render)return void(this._render_wait=!0);this._render_wait=!1,this.clear_view(),this._evs_layer={};for(var e=0;e<this.layers.length;e++)this._evs_layer[this.layers[e].name]=[];for(var t=this.get_visible_events(),e=0;e<t.length;e++)this._evs_layer[t[e].layer]&&this._evs_layer[t[e].layer].push(t[e]);if("month"==this._mode){for(var a=[],e=0;e<this.layers.length;e++)this.layers[e].visible&&(a=a.concat(this._evs_layer[this.layers[e].name]));

this._t_render_view_data(a)}else for(var e=0;e<this.layers.length;e++)if(this.layers[e].visible){var n=this._evs_layer[this.layers[e].name];this._t_render_view_data(n)}},e._render_v_bar=function(t,a,n,i,r,l,d,o,s){var _=t.id;-1==d.indexOf("<div class=")&&(d=e.templates["event_header_"+t.layer]?e.templates["event_header_"+t.layer](t.start_date,t.end_date,t):d),-1==o.indexOf("<div class=")&&(o=e.templates["event_text_"+t.layer]?e.templates["event_text_"+t.layer](t.start_date,t.end_date,t):o);var c=document.createElement("DIV"),u="dhx_cal_event",h=e.templates["event_class_"+t.layer]?e.templates["event_class_"+t.layer](t.start_date,t.end_date,t):e.templates.event_class(t.start_date,t.end_date,t);

h&&(u=u+" "+h);var p='<div event_id="'+_+'" class="'+u+'" style="position:absolute; top:'+n+"px; left:"+a+"px; width:"+(i-4)+"px; height:"+r+"px;"+(l||"")+'">';return p+='<div class="dhx_header" style=" width:'+(i-6)+'px;" >&nbsp;</div>',p+='<div class="dhx_title">'+d+"</div>",p+='<div class="dhx_body" style=" width:'+(i-(this._quirks?4:14))+"px; height:"+(r-(this._quirks?20:30))+'px;">'+o+"</div>",p+='<div class="dhx_footer" style=" width:'+(i-8)+"px;"+(s?" margin-top:-1px;":"")+'" ></div></div>',
c.innerHTML=p,c.style.zIndex=100,c.firstChild},e.render_event_bar=function(t){var a=this._els.dhx_cal_data[0],n=this._colsS[t._sday],i=this._colsS[t._eday];i==n&&(i=this._colsS[t._eday+1]);var r=this.xy.bar_height,l=this._colsS.heights[t._sweek]+(this._colsS.height?this.xy.month_scale_height+2:2)+t._sorder*r,d=document.createElement("DIV"),o=t._timed?"dhx_cal_event_clear":"dhx_cal_event_line",s=e.templates["event_class_"+t.layer]?e.templates["event_class_"+t.layer](t.start_date,t.end_date,t):e.templates.event_class(t.start_date,t.end_date,t);

s&&(o=o+" "+s);var _='<div event_id="'+t.id+'" class="'+o+'" style="position:absolute; top:'+l+"px; left:"+n+"px; width:"+(i-n-15)+"px;"+(t._text_style||"")+'">';t._timed&&(_+=e.templates["event_bar_date_"+t.layer]?e.templates["event_bar_date_"+t.layer](t.start_date,t.end_date,t):e.templates.event_bar_date(t.start_date,t.end_date,t)),_+=e.templates["event_bar_text_"+t.layer]?e.templates["event_bar_text_"+t.layer](t.start_date,t.end_date,t):e.templates.event_bar_text(t.start_date,t.end_date,t)+"</div>)",
_+="</div>",d.innerHTML=_,this._rendered.push(d.firstChild),a.appendChild(d.firstChild)},e.render_event=function(t){var a=e.xy.menu_width;if(e.getLayer(t.layer).noMenu&&(a=0),!(t._sday<0)){var n=e.locate_holder(t._sday);if(n){var i=60*t.start_date.getHours()+t.start_date.getMinutes(),r=60*t.end_date.getHours()+t.end_date.getMinutes()||60*e.config.last_hour,l=Math.round((60*i*1e3-60*this.config.first_hour*60*1e3)*this.config.hour_size_px/36e5)%(24*this.config.hour_size_px)+1,d=Math.max(e.xy.min_event_height,(r-i)*this.config.hour_size_px/60)+1,o=Math.floor((n.clientWidth-a)/t._count),s=t._sorder*o+1;

t._inner||(o*=t._count-t._sorder);var _=this._render_v_bar(t.id,a+s,l,o,d,t._text_style,e.templates.event_header(t.start_date,t.end_date,t),e.templates.event_text(t.start_date,t.end_date,t));if(this._rendered.push(_),n.appendChild(_),s=s+parseInt(n.style.left,10)+a,l+=this._dy_shift,_.style.zIndex=this._layers_zindex[t.layer],this._edit_id==t.id){_.style.zIndex=parseInt(_.style.zIndex)+1;var c=_.style.zIndex;o=Math.max(o-4,e.xy.editor_width);var _=document.createElement("DIV");_.setAttribute("event_id",t.id),
this.set_xy(_,o,d-20,s,l+14),_.className="dhx_cal_editor",_.style.zIndex=c;var u=document.createElement("DIV");this.set_xy(u,o-6,d-26),u.style.cssText+=";margin:2px 2px 2px 2px;overflow:hidden;",u.style.zIndex=c,_.appendChild(u),this._els.dhx_cal_data[0].appendChild(_),this._rendered.push(_),u.innerHTML="<textarea class='dhx_cal_editor'>"+t.text+"</textarea>",this._quirks7&&(u.firstChild.style.height=d-12+"px"),this._editor=u.firstChild,this._editor.onkeypress=function(t){if((t||event).shiftKey)return!0;

var a=(t||event).keyCode;a==e.keys.edit_save&&e.editStop(!0),a==e.keys.edit_cancel&&e.editStop(!1)},this._editor.onselectstart=function(e){return(e||event).cancelBubble=!0,!0},u.firstChild.focus(),this._els.dhx_cal_data[0].scrollLeft=0,u.firstChild.select()}if(this._select_id==t.id){_.style.zIndex=parseInt(_.style.zIndex)+1;for(var h=this.config["icons_"+(this._edit_id==t.id?"edit":"select")],p="",v=0;v<h.length;v++)p+="<div class='dhx_menu_icon "+h[v]+"' title='"+this.locale.labels[h[v]]+"'></div>";

var m=this._render_v_bar(t.id,s-a+1,l,a,20*h.length+26,"","<div class='dhx_menu_head'></div>",p,!0);m.style.left=s-a+1,m.style.zIndex=_.style.zIndex,this._els.dhx_cal_data[0].appendChild(m),this._rendered.push(m)}}}},e.filter_agenda=function(t,a){var n=e.getLayer(a.layer);return n&&n.visible}})});